package com.feng.controller;

import com.feng.domain.ResponseResult;
import com.feng.domain.dto.GetUserListDto;
import com.feng.domain.dto.SystemUpdateUserDto;
import com.feng.domain.dto.SystemUserAddDto;
import com.feng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PreAuthorize("@ps.hasPermission('system:user:query')")
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, GetUserListDto listDto){
        return userService.getUserList(pageNum, pageSize, listDto);
    }

    @PreAuthorize("@ps.hasPermission('system:user:add')")
    @PostMapping
    public ResponseResult addUser(@RequestBody SystemUserAddDto addDto){
        return userService.addUser(addDto);
    }

    @PreAuthorize("@ps.hasPermission('system:user:remove')")
    @DeleteMapping("/{id}")
    public ResponseResult delUser(@PathVariable("id") List<Long> ids){
        return userService.delUser(ids);
    }

    @PreAuthorize("@ps.hasPermission('system:user:edit')")
    @GetMapping("/{id}")
    public ResponseResult getUser(@PathVariable("id") Long id){
        return userService.getUser(id);
    }

    @PreAuthorize("@ps.hasPermission('system:user:edit')")
    @PutMapping
    public ResponseResult updateUser(@RequestBody SystemUpdateUserDto userDto){
        return userService.updateUser(userDto);
    }
}
